/**
 * 定义菜单权限相关的接口
 */
import request from '@/utils/request'
import { MenuParamsData, PermissionListResponseData } from '@/api/acl/menu/type'

/**
 * 定义接口地址
 */
enum API {
  // 获取全部菜单与按钮数据
  ALL_MENU_BUTTON_URL = '/admin/acl/permission',
  // 添加菜单
  ADD_MENU_URL = '/admin/acl/permission/save',
  // 修改菜单
  UPDATE_MENU_URL = '/admin/acl/permission/update',
  // 递归删除菜单
  DELETE_MENU_URL = '/admin/acl/permission/remove/',
}

/**
 * 获取全部菜单与按钮数据
 */
export const reqGetAllMenu = () => {
  return request.get<any, PermissionListResponseData>(API.ALL_MENU_BUTTON_URL)
}

/**
 * 添加或修改菜单
 */
export const reqAddOrUpdateMenu = (menu: MenuParamsData) => {
  if (menu.id) {
    return request.put<any, any>(API.UPDATE_MENU_URL, menu)
  } else {
    return request.post<any, any>(API.ADD_MENU_URL, menu)
  }
}

/**
 * 删除菜单
 */
export const reqDeleteMenu = (id: number | string) => {
  return request.delete<any, any>(API.DELETE_MENU_URL + id)
}
